import { createSlice } from "@reduxjs/toolkit";
import { configureStore } from "@reduxjs/toolkit";

const initialState = {
    connectedDevices:[],
    currentSelectedDevice:{}
}
const deviceSlice = createSlice({
    name: "devices",
    initialState,
    reducers: {
        addConnectedDevice(state, action) {
            state.connectedDevices.push(action.payload)
        },
        removeDevice(state, action) {
        },
        setCurrentConnectedDevice(state, action) {
            state.currentSelectedDevice = action.payload
        }
    }
})

export const { addConnectedDevice, removeDevice,setCurrentConnectedDevice } = deviceSlice.actions

export const store = configureStore({
    middleware: getDefaultMiddleware => getDefaultMiddleware({
        serializableCheck: false,
    }),
    reducer: {
        devices: deviceSlice.reducer
    }
})

export default store